Fix Eshell call to 'string-suffix-p' when checking for trailing newline
authorJim Porter <jporterbugs@gmail.com>
Mon, 21 Jul 2025 04:17:05 +0000 (21:17 -0700)
committerJim Porter <jporterbugs@gmail.com>
Tue, 22 Jul 2025 01:47:43 +0000 (18:47 -0700)
* lisp/eshell/esh-io.el (eshell--output-maybe-n): Fix call.

* test/lisp/eshell/esh-io-tests.el
(esh-io-test/output-newline/add-newline)
(esh-io-test/output-newline/no-newline)
(esh-io-test/output-newline/no-extra-newline): New tests (bug#79063).

lisp/eshell/esh-io.el
test/lisp/eshell/esh-io-tests.el

index ff275560a04934171e61e353fe72139e263de137..1b474d988a7e6358bd82385c8a6b2b80740a873e 100644 (file)
@@ -569,7 +569,7 @@ ends in a newline."
   (eshell-output-object object handle)
   (when (and eshell-ensure-newline-p
              (not (and (stringp object)
-                       (string-suffix-p object "\n"))))
+                       (string-suffix-p "\n" object))))
     (eshell-maybe-output-newline handle)))
 
 (defsubst eshell-print-maybe-n (object)
index 0b25ad812fa29ae06e6bc7bd0fdc45d3d5e4ef42..e6bc5c9809c19478bbe7ee77509c3d265543bcb3 100644 (file)
 
 ;;; Tests:
 
+\f
+;; Newlines
+
+(ert-deftest esh-io-test/output-newline/add-newline ()
+  "Ensure we add a newline when writing a string to stdout."
+  (with-temp-eshell
+    (eshell-match-command-output "(concat \"hello\")" "\\`hello\n\\'")))
+
+(ert-deftest esh-io-test/output-newline/no-newline ()
+  "Ensure we don't add a newline when writing a string to a buffer."
+  (eshell-with-temp-buffer bufname ""
+    (with-temp-eshell
+      (eshell-match-command-output
+       (format "(concat \"hello\") > #<%s>" bufname)
+       "\\`\\'"))
+    (should (equal (buffer-string) "hello"))))
+
+(ert-deftest esh-io-test/output-newline/no-extra-newline ()
+  "Ensure we don't add an extra newline when writing to stdout."
+  (with-temp-eshell
+    (eshell-match-command-output "(concat \"hello\n\")" "\\`hello\n\\'")))
+
 \f
 ;; Basic redirection